<?php

/**
 * Subclass for performing query and update operations on the 'post' table.
 *
 * 
 *
 * @package lib.model
 */ 
class PostPeer extends BasePostPeer
{
  public static function retrieveByHandle($handle)
  {
  	$c = new Criteria();
  	$c->add(PostPeer::HANDLE, $handle);
  	
  	return PostPeer::doSelectOne($c); 
  }
  
  public static function retrieveRandom()
  {
  	$c = new Criteria();
  	$c->addDescendingOrderByColumn(PostPeer::ID);
  	$c->setLimit('1');
  	
  	$last = PostPeer::doSelectOne($c);
  	
  	$rand = rand(1, $last->getId());
  	
  	$c->add(PostPeer::ID, $rand, Criteria::LESS_EQUAL);
  	
  	return PostPeer::doSelectOne($c); 
  }
  
  public static function retrieveByPkAndUserId($pk, $user_id)
  {
  	$c = new Criteria();
  	$c->add(PostPeer::USER_ID, $user_id);
  	$c->add(PostPeer::ID, $pk);
  	
  	return self::doSelectOne($c);
  }
  
  public static function retrieveRecent()
  {
  	$c = new Criteria();
  	$c->addDescendingOrderByColumn(PostPeer::PUBLISHED);
  	$c->setLimit(sfConfig::get('app_limit_recent'));
  	
  	return self::doSelect($c);
  }
}
